<!DOCTYPE html>
<html lang="en" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <link rel="stylesheet" href="/layui/css/layui.css">
  <link rel="stylesheet" href="/css/custom.form.css">
</head>
<body>
<div class="panel panel-default operation" hidden>
  <div class="panel-heading title"></div>
	<div class="layui-card-body">
	<form class="layui-form" action="" lay-filter="info" style="margin-top: 10px">
      <input name="id" hidden/>
        <div class="layui-form-item">
      <label class="layui-form-label">车辆吨数</label>
      <div class="layui-input-block">
        <input type="ton1" name="ton1" placeholder="请输入车辆吨数" autocomplete="off" class="layui-input">
      </div>
    </div>
    
    
     <div class="layui-form-item">
      <label class="layui-form-label">转轮吨数</label>
      <div class="layui-input-block">
        <input type="ton2" name="ton2" placeholder="请输入转轮吨数" autocomplete="off" class="layui-input">
      </div>
    </div>
    
    
     <div class="layui-form-item">
      <label class="layui-form-label">升降机吨数</label>
      <div class="layui-input-block">
        <input type="ton3" name="ton3" placeholder="请输入升降机吨数" autocomplete="off" class="layui-input">
      </div>
    </div>
    
    
  	<div class="layui-form-item">
	  <div class="layui-input-block">
	    <button type="submit" class="layui-btn" lay-submit="" lay-filter="submit">保存</button>
	    <button  class="layui-btn layui-btn-primary" id="btn_cancel">返回</button>
	  </div>
	</div>
	</form>
	</div>
</div>

<div class="table_div">
  <div id="searchParam">
    <div class="layui-form-item">
		<div class="layui-input-inline">
        <input type="text" id="createTimeInput" class="layui-input"  autocomplete="off" placeholder="请输入时间范围">
      </div>
      
       <div class="layui-input-inline ">
        <button class="layui-btn" onclick="search()"  id="search">查询</button>
        <!-- <button class="layui-btn" onclick="exportData()"  id="export">导出</button> -->
      </div>
    </div>

  </div>
  <table class="layui-table" id="showTable" lay-filter="showTable" ></table>
</div>
<script type="text/html" id="toolbar">
  <!-- <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" lay-event="add" >添加</button>
    <button class="layui-btn layui-btn-sm" lay-event="batchDeleted">删除</button>
  </div> -->
</script>
<script type="text/html" id="tool">
  <a class="layui-btn layui-btn-xs" lay-event="edit" >编辑</a>
  <!-- <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a> -->
</script>

</body>
</html>
<script src="/layui/layui.all.js"></script>
<script src="/js/core.util.js"></script>
<script>
  //获取token
  var token = CoreUtil.getData("access_token");
  //地址栏转义token中的#号
  var tokenQuery = token.replace("#", "%23");
  var tableIns1;
  var table = layui.table;
  var form = layui.form;
  var layer = layui.layer;
  var $ = jQuery = layui.jquery;
  var laydate = layui.laydate;

  layui.use(['table', 'layer', 'laydate'], function () {

	  laydate.render({
			elem : '#createTimeInput',
			type : 'date',
			range : '至',
			done : function(value, date, endDate) {
				if (value != null && value != undefined
						&& value != "") {
					startTime = value.split("至")[0];
					endTime = value.split("至")[1];
					
				} else {
					startTime = null;
					endTime = null;
				}

			}
		});
	  
    //加载table
    tableIns1 = table.render({
      elem: '#showTable'
      , contentType: 'application/json'
      , headers: {"authorization": token}
      , page: true //开启分页
      , url: '/nr/calculate/list' //数据接口
      , where: {
        	  id : 'oreCollect',
      } // 初始化时的过滤条件
      , method: 'POST'
      , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
        return {
          "code": res.code, //解析接口状态
          "msg": res.msg, //解析提示文本
          "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
          "data": CoreUtil.isEmpty(res.data) ? null : res.data.records //解析数据列表
        }
      }
      , cols: [
        [
          {type: 'checkbox', fixed: 'left'},
          {field: 'id', title: '主键', sort: true, hide: true},
          {field: 'ton1', title: '车辆吨数', sort: true},
          {field: 'ton2', title: '转轮吨数', sort: true},
          {field: 'ton3', title: '升降机吨数', sort: true},
          
          {field: 'createTime', title: '创建时间', sort: true},
          {width: 120, toolbar: "#tool", title: '操作'}
        ]
      ]
      , toolbar: '#toolbar'
    });


    //表头工具
    table.on('toolbar(showTable)', function(obj){
      switch(obj.event){
        case 'batchDeleted':
          var checkStatus = table.checkStatus(obj.config.id);
          var data = checkStatus.data;
          if(data.length==0){
            layer.msg("请选择要批量删除的列");
          }else {
            var ids = [];
            $(data).each(function (index,item) {
              ids.push(item.id);
            });
            tipDialog(ids);
          }
          break;
        case 'add':
          $(".table_div").hide();
          $(".operation").show();
          $(".title").html("新增");
          $(".operation input[name=id]").val("");
          $(".operation input[name=ton1]").val("");
          $(".operation input[name=createTime]").val("");
          break;
      };
    });
    //列操作
    table.on('tool(showTable)',function (obj) {
      var data = obj.data;
      switch (obj.event) {
        case 'del':
          var ids=[];
          ids.push(data.id);
          tipDialog(ids);
          break;
        case 'edit':
          $(".table_div").hide();
          $(".operation").show();
          $(".title").html("编辑");
          $(".operation input[name=id]").val(data.id);
          $(".operation input[name=ton1]").val(data.ton1);
          $(".operation input[name=ton2]").val(data.ton2);
          $(".operation input[name=ton3]").val(data.ton3);
          
          $(".operation input[name=createTime]").val(data.createTime);
          break;
      }
    });

    //删除
    var tipDialog=function (ids) {
      layer.open({
        content: "确定要删除么?",
        yes: function(index, layero){
          layer.close(index); //如果设定了yes回调，需进行手工关闭
          CoreUtil.sendDelete("/nr/calculate/delete",ids,function (res) {
            layer.msg(res.msg, {time:1000},function () {
              search();
            });
          });
        }
      });
    };

    //返回
    $("#btn_cancel").click(function() {
      $(".table_div").show();
      $(".operation").hide();
      return false;
    });

    //监听保存
    form.on('submit(submit)', function(data){
      if(data.field.id===undefined || data.field.id===null || data.field.id===""){
        
      }else {
        CoreUtil.sendPut("/nr/calculate/update",data.field,function (res) {
          $(".table_div").show();
          $(".operation").hide();
          search();
        });
      }

      return false;
    });
  });

  /* //导出
  function exportData(){
	  var createTimeInput = $("#createTimeInput").val();
	  var messageMsegtypeInput = $("#messageMsegtypeInput").val();
	  var arr = createTimeInput.split('至');
	  
	  var map = {
			  createTimeStart : arr[0],
				createTimeEnd : arr[1],
	  }
	  
	  CoreUtil.sendPost("/gas/maintain/exportData",map,function (res) {
		  if(res.code == 0){
			var file = res.data[2];
			window.open(file,'_blank');
		  }else{
			layer.msg(res.msg);
			return false;
		  }
          
	  });
  } */
  
  //执行查询
  function search() {
	  var createTimeInput = $("#createTimeInput").val();
	  var messageMsegtypeInput = $("#messageMsegtypeInput").val();
	  var arr = createTimeInput.split('至');
	  
	  //这里以搜索为例
    tableIns1.reload({
      where: { //设定异步数据接口的额外参数，任意设
    	  createTimeStart : arr[0],
			createTimeEnd : arr[1]
      }
      , page: {
        curr: 1 //重新从第 1 页开始
      }
    });
  };
</script>